﻿
/*
HTML Syntax rule for SupertreeTextEditor

Author: Feng Weiguo ( 冯卫国 )
Mail: forxm@21cn.com
Web: www.supertree.org

All Rights Reserved, 2008-9

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
*/

$ec.$preload(
	"org.supertree.editor.RuleHtml",
	function()
	{
		var RC= $ec.$import("org.supertree.editor.RuleCompiler").prototype;
		
		this.prototype=
		{
//////////////////////////////
// EC-CLASS BODY
//////////////////////////////
			RuleHtml: function()
			{
				throw "can not instantiate RuleHtml";
			},
			
			sName: "Html",
			
			sEndStack: "|0|",
			
			aInsert:[
				"&lt;TABLE&gt;","\n<TABLE>\n    <TR>\n        <TD>\n        </TD>\n    </TR>\n</TABLE>",
				"&lt;TR&gt;","\n<TR>\n    <TD>\n    </TD>\n</TR>",
				"&lt;TD&gt;","\n<TD>\n</TD>"
				]
			
//////////////////////////////
// END EC-CLASS BODY	//NOTE - DO NOT CHANGE THESE 3 LINES, the ide wizards may use them.
//////////////////////////////
		}
		
		//construct rule
		
		//auxiliary rule item
		var _rule= this.prototype._rule=
		{
			sHtmlElement: RC.ToIgnoreCase("a|acronym|address|applet|area|b|base|baseFont|bdo|bgSound|big|blockQuote|body|br|button|caption|center|cite|code|col|colGroup|COMMENT|dd|del|dfn|dir|div|dl|dt|em|embed|fieldSet|font|form|frame|frameSet|head|hn|hr|html|i|iframe|img|IMPORT|input|ins|isIndex|kbd|label|legend|li|link|listing|map|marquee|menu|meta|noBR|noFrames|noScript|object|ol|optGroup|option|p|param|plainText|pre|q|rt|ruby|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tBody|td|textArea|tFoot|th|tHead|title|tr|tt|u|ul|var|wbr|xml|xmp"),
			//refer RuleXslt
			sHtmlAttr: /*RC.ToIgnoreCase*/("ACCESSKEY|ACTION|ADCREATED|ADVERTISEMENTFILE|ALIGN|ALINK|ALLOWCUSTOMPAGING|ALLOWPAGING|ALLOWSORTING|ALT|ALTERNATETEXT|ALTERNATINGITEMSTYLE|ALTERNATINGITEMTEMPLATE|APPLYSTYLE|ATTRIBUTES|AUTOGENERATECOLUMNS|AUTOPOSTBACK|BACKCOLOR|BACKGROUND|BACKIMAGEURL|BEHAVIOR|BGCOLOR|BGPROPERTIES|BORDER|BORDERCOLOR|BORDERCOLORDARK|BORDERCOLORLIGHT|BORDERSTYLE|BORDERWIDTH|CANCELCOMMAND|CAUSESVALIDATION|CELLPADDING|CELLSPACING|CHARSET|CHECKCHANGED|CHECKED|CLASS|CLASSID|CLEAR|CLICK|CODEBASE|COLOR|COLS|COLSPAN|COLUMNS|COLUMNSPAN|COMMAND|COMMANDARGUMENT|COMMANDNAME|COMMANDARGUMENT|COMMANDNAME|CONTENT|CONTROLS|CONTROLTOCOMPARE|CONTROLTOVALIDATE|COORDS|COPYFROM|CSSCLASS|DATA|DATAFIELD|DATAFORMATSTRING|DATAKEYFIELD|DATAMEMBER|DATANAVIGATEURLFIELD|DATANAVIGATEURLFORMATSTRING|DATASOURCE|DATATEXTFIELD|DATAVALUEFIELD|DAYHEADERSTYLE|DAYNAMEFORMAT|DAYRENDER|DAYSTYLE|DECLARE|DEFER|DELETECOMMAND|DIR|DIRECTION|DOCUMENT|DOCUMENTCONTENT|DOCUMENTSOURCE|DYNSRC|EDITCOMMAND|EDITITEMSTYLE|EDITITEMTEMPLATE|ENABLED|ENABLEVIEWSTATE|ENCTYPE|EXTRACTTEMPLATEROWS|FACE|FIRSTDAYOFWEEK|FONT|FONT-BOLD|FONT-ITALIC|FONT-NAME|FONT-NAMES|FONT-OVERLINE|FONT-SIZE|FONT-STRIKEOUT|FONT-UNDERLINE|FOOTERSTYLE|FOOTERTEMPLATE|FOOTERTEXT|FORECOLOR|FRAMEBORDER|FRAMESPACING|GRIDLINES|GROUPNAME|HEADERSTYLE|HEADERTEMPLATE|HEADERTEXT|HEIGHT|HORIZONTALALIGN|HREF|HSPACE|HTTP-EQUIV|ID|IMAGEALIGN|IMAGEURL|IMPRESSIONS|INNERHTML|INNERTEXT|ISMAP|ITEMCOMMAND|ITEMCREATED|ITEMDATABOUND|ITEMSTYLE|ITEMTEMPLATE|KEYWORD|KEYWORDFILTER|LANGUAGE|LEFTMARGIN|LINK|LOOP|MARGINHEIGHT|MARGINWIDTH|MARKINGHEIGHT|MAXIMUMVALUE|MAXLENGTH|MEDIA|MERGESTYLE|MERGEWITH|METHOD|MINIMUMVALUE|MODE|MULTIPLE|NAME|NAVIGATEURL|NEXTMONTHTEXT|NEXTPAGETEXT|NEXTPREVFORMAT|NEXTPREVSTYLE|NOHREF|NOSHADE|NOWRAP|ONADCREATED|ONBLUR|ONCANCELCOMMAND|ONCHECKEDCHANGED|ONCLICK|ONCOMMAND|ONDAYRENDER|ONDBLCLICK|ONDELETECOMMAND|ONEDITCOMMAND|ONFOCUS|ONITEMCOMMAND|ONITEMCREATED|ONKEYDOWN|ONKEYPRESS|ONKEYUP|ONLOAD|ONMOUSEDOWN|ONMOUSEOUT|ONMOUSEOVER|ONMOUSEUP|ONPAGEINDEXCHANGED|ONSELECTEDINDEXCHANGED|ONSELECTIONCHANGED|ONSERVERCHANGE|ONSERVERCLICK|ONSERVERVALIDATE|ONSORTCOMMAND|ONTEXTCHANGED|ONUNLOAD|ONUPDATECOMMAND|ONVISIBLEMONTHCHANGED|OPTIONAL|OTHERMONTHDAYSTYLE|PAGEINDEXCHANGED|PAGERSTYLE|PAGESIZE|PALETTE|POSTEDFILE|PREVMONTHTEXT|PREVPAGETEXT|PROMPT|READONLY|REL|REPEATCOLUMNS|REPEATDIRECTION|REPEATLAYOUT|REV|ROWS|ROWSPAN|RULES|RUNAT|SCEME|SCROLLAMOUNT|SCROLLDELAY|SCROLLING|SELECTED|SELECTEDDATE|SELECTEDDATES|SELECTEDDAYSTYLE|SELECTEDINDEX|SELECTEDINDEXCHANGED|SELECTEDITEMSTYLE|SELECTEDITEMTEMPLATE|SELECTIONMODE|SELECTMONTHTEXT|SELECTORSTYLE|SELECTWEEKTEXT|SEPARATORSTYLE|SEPARATORTEMPLATE|SERVERCHANGE|SERVERVALIDATE|SHAPE|SHAPES|SHOWDAYHEADER|SHOWFOOTER|SHOWGRIDLINES|SHOWHEADER|SHOWNEXTPREVMONTH|SHOWTITLE|SIZE|SORTEXPRESSION|SPAN|SRC|STANDBY|START|STYLE|TABINDEX|TARGET|TEXT|TEXTALIGN|TEXTCHANGED|TEXTMODE|TITLEFORMAT|TITLESTYLE|TODAYSDATE|TODAYDAYSTYLE|TOOLTIP|TOPMARGIN|TOOLTIP|TOPMARGIN|TRANSFORM|TRANSFORMSOURCE|TYPE|URL|USEMAP|VALIDATE|VALIDATIONEXPRESSION|VALIGN|VALUE|VALUETYPE|VERTICALALIGN|VISIBLEDATE|VISIBLEMONTHCHANGED|VLINK|VSPACE|WEEKENDDAYSTYLE|WIDTH|WRAP"),

			ruleHtmlAttrValue:
				[
					"([\\s\\u00A0]+)|(=)|([^\\s\\u00A0=])|($)",
					["","",0],		// spaces
					["","",1,"",	// =
						[
							"([\\s\\u00A0]+)|(')|(\")|([^\\s\\u00A0'\"])|($)",
							["","",0],	// spaces
							["Fuchsia","",1,"",	// '
								[
									"(')|($)",
									["Fuchsia","Fuchsia",-3],	// string finish
									["","Fuchsia",0]		// next line, xml attr
								]
							],
							["Fuchsia","",1,"",		// "
								[
									"(\")|($)",
									["Fuchsia","Fuchsia",-3],	// string finish
									["","Fuchsia",0]		// next line, xml attr
								]
							],
							["void","err",-2],	// bad char
							["","",0]	// next line
						]
					],
					["void","err",-1],	// bad char
					["err","err",0]		// next line
				],

			RuleHtmlAttr: function( colorTagEnd )
				{
					var a= [
						"(\\/>)|(>)|([\\s\\u00A0]+|=)|((?:"+this.sHtmlAttr+")\\b)|(\\b[a-zA-Z0-9-]+\\b)|(<\\/)|(<)|($)",
						["","",-2],		// tag end />
						["","",-2,],		// tag end >
						["","",0],		// spaces and '='
						["Blue","err",1,"",this.ruleHtmlAttrValue],		// tag attribute
						["alert","err",1,"",this.ruleHtmlAttrValue],		// unknown tag attribute
						["void","err",-2,"",],		// </, must be pop back to this ri
						["void","errx",-2],	// bad <
						["","",0]		// next line
						];
					
					a.regFlags="ig";
					
					return a;
				}
		}

		this.prototype.rule=
		[
			//"(<!--)|(<!\\[CDATA\\[)|(<\\?)|(<\\/)|(<)|($)",
			"(<!--)|(<!\\[CDATA\\[)|(<\\?)|(<!)|(<\\/?)|($)",
			["Green","",1,"",	// <!--
				[
					"(-->)|($)",
					["Green","Green",-1],		// -->
					["Green","Green",0]		// next line
				]
			],
			["Brown","",1,"",	// <![CDATA[
				[
					"(\\]\\]>)|($)",
					["Brown","Brown",-1],	// ]]>
					["","Brown",0]			// next line
				]
			],
			["Blue","",1,"",	// <?
				[
					"(\\?>)|(\\b(?:version|encoding)\\b)|($)",
					["Blue","Blue",-1],	// ]]>
					["Brown","Blue",0],	// for <?xml... key word
					["","Blue",0]			// next line
				]
			],
			["Blue","",1,"",	// <!
				[
					"(>)|($)",
					["Blue","Blue",-1],	// >
					["","Blue",0]			// next line
				]
			],
			//["void","",-1],	//	</, pop back
			["","",1,"",		// < or </
				[
					"((?:"+_rule.sHtmlElement+")\\b)|([a-zA-Z][a-zA-Z0-9]*)|($)",
					["BlueB","err",1,"", _rule.RuleHtmlAttr('BlueB')],	// html tag
					["alert","err",1,"", _rule.RuleHtmlAttr('alert')],	// unknown html tag
					["err","",0]	// next line
				]
			],
			["","",0]	// next line
		];
		
		RC.Compile(this.prototype);
	}
);
